<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<link rel="shortcut icon" href="http://yangwenxue.oschina.io/images/favicon.ico">
		<link rel="stylesheet" href="http://yangwenxue.oschina.io/css/font-awesome.min.css" type="text/css">
		<link rel="stylesheet" href="http://yangwenxue.oschina.io/css/boostrap/bootstrap-4.0.0-beta.1.css"> </head>

	<body>
		<div class="py-5">
			<div class="container">
				<div class="row">
					<div class="col-md-12">
						<ul class="breadcrumb" style="margin-bottom: 0px; margin-top: 0px;">
							<li class="breadcrumb-item">
								<a href="company_index.html">面试资源</a>
							</li>
							<li class="breadcrumb-item">
								<a href="company_list.html">公司列表</a>
							</li>
							<li class="breadcrumb-item active">添加公司</li>
						</ul>
					</div>
				</div>
			</div>
		</div>
		<div class="py-3">
			<div class="container">
				<div class="row">
					<div class="col-md-12">
						<form class="" method="post" id="add-company">
							<div class="form-group"> <label>公司名称</label>
								<input type="text" name="companyName" class="form-control" onblur="checkIsEdu()" placeholder="公司名称"> </div>
							<div class="form-group"> <label>公司地址</label>
								<input type="text" name="companyAddress" class="form-control" placeholder="公司地址"> </div>
							<div class="form-group"> <label>联系人<br></label>
								<input type="text" name="employeeName" class="form-control" placeholder="联系人"> </div>
							<div class="form-group"> <label>联系人电话</label>
								<input type="text" name="companyPhone" class="form-control" placeholder="联系人电话"> </div>
							<div class="form-group"> <label>是否要求学历</label>
								<select class="form-control" name="isEdu">
									<option value="1">是</option>
									<option value="0">否</option>
								</select>
							</div>
							<div class="form-group"> <label>学科</label>
								<select class="form-control" name="recruitTypeId">
									<option>--请选择--</option>
								</select>
							</div>
							<button type="button" onclick="addCompany()" class="btn btn-primary">添加</button>
						</form>
					</div>
				</div>
			</div>
		</div>
		<div class="container">
			<div class="row">
				<div class="col-md-12 mt-3 text-center">
					<p>© 2017-Yokol.top版权所有-
						<a href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=17061202" target="_blank">&nbsp;京ICP备17061202号 </a>
					</p>
				</div>
			</div>
		</div>
		<script src="http://yangwenxue.oschina.io/js/jquery/jquery.min.js"></script>
		<script type="text/javascript" src="../js/common.js"></script>
		<script type="application/javascript">
			$(function() {
				initDict();
			})

			function initDict() {
				$.ajax({
					url: resPath_work + "dict/getDictList",
					type: "post",
					dataType: 'json',
					success: function(data) {
						$("select[name=recruitTypeId]").html("");
						var resList = data.data;
						var htmlCode = '';
						for(var i = 0; i < resList.length; i++) {
							var code = resList[i];
							htmlCode += '<option value="' + code.id + '">' + code.dicValue + '</option>';
						}
						$("select[name=recruitTypeId]").append(htmlCode);
					},
					error: function() {
						alert("获取字典列表失败");
					}
				});
			};

			// 添加公司招聘信息
			function addCompany() {
				$.ajax({
					url: resPath_work + "company/addCompany",
					type: "post",
					data: $("#add-company").serializeJson(),
					dataType: 'json',
					beforeSend: function(XMLHttpRequest) {
						// 禁用按钮防止重复提交
						$(".btn-primary").attr({
							disabled: "disabled"
						});
					},
					complete: function() {
						// 禁用按钮防止重复提交
						$(".btn-primary").removeAttr("disabled");
					},
					success: function(data) {
						if(data.status == "500") {
							alert(data.msg);
						} else {
							alert("添加成功，单击确认返回列表页面");
							window.location.href = "company_list.html";
						}
					},
					error: function() {
						alert("添加失败");
					}
				});
			};

			// 检查该公司是否有培训经历
			function checkIsEdu() {
				var companyName = $("input[name=companyName]").val();
				if(companyName == undefined || companyName == null || companyName == '') {
					alert("请输入公司名称！！");
					return false;
				}
				$.ajax({
					url: resPath_work + "company/checkIsEdu",
					type: "post",
					data: {
						companyName: companyName
					},
					dataType: 'json',
					success: function(data) {
						if(data != undefined && data.data > 0) {
							alert("该公司曾经有过" + data.data + "培训招聘信息，确认继续添加吗？");
						}
						console.log("查询公司是否有培训记录信息....");
						console.log(data);
					},
					error: function() {
						alert("网络错误，无法检查公司是否为培训机构");
					}
				});
			}
		</script>
	</body>

</html>